package com.example.demo3.service;

import com.example.demo3.domain.vo.UserVo;
import com.example.demo3.mapper.LoginMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class LoginService  {


    private final  LoginMapper loginMapper;


    public UserVo getUserByName(String name) {

        //  根据用户查角色 ，根据角色查权限 ， 树解构查询 ；

        return loginMapper.getUserByName(name);
    }

    /**
     * 模拟数据库查询
     *
     * @param userName 用户名
     * @return User
     */
//    private UserVo getMapByName(String userName) {
//        Permissions permissions1 = new Permissions(1, "query");
//        Permissions permissions2 = new Permissions(2, "add");
//        Permissions permissions3 = new Permissions(3, "list");
//        Permissions permissions4 = new Permissions(4, "user/add");
//        Set<Permissions> permissionsSet = new HashSet<>();
//        permissionsSet.add(permissions1);
//        permissionsSet.add(permissions2);
//        permissionsSet.add(permissions3);
//        permissionsSet.add(permissions4);
//        Role role = new Role(1, "admin", permissionsSet);
//        Set<Role> roleSet = new HashSet<>();
//        roleSet.add(role);
//        UserVo user = new UserVo(1, "wsl", "123456", roleSet);
//        Map<String, UserVo> map = new HashMap<>();
//        map.put(user.getUserName(), user);
//
//        Set<Permissions> permissionsSet1 = new HashSet<>();
//        permissionsSet1.add(permissions1);
//        Role role1 = new Role(2, "user", permissionsSet1);
//        Set<Role> roleSet1 = new HashSet<>();
//        roleSet1.add(role1);
//        UserVo user1 = new UserVo(2, "zhangsan", "123456", roleSet1);
//        map.put(user1.getUserName(), user1);
//        return map.get(userName);
//    }


}
